package com.fruits.login.model;

import com.fruits.login.dto.LoginDto;

import javax.validation.constraints.NotBlank;
import java.util.Date;

public class PlayerLoginInfo {
    //时间戳
//    @TimePastConstraion(message = "时间戳错误")
    private Date timestamp;
    //联合id:传入中有该参数且数据库中有该参数则原封不动返回,若没有则后端生成一个唯一的uid并返回
    private String uid;
    //物理地址:唯一约束
    @NotBlank(message = "MAC不能为空")
    private String deviceMac;
    //玩家类型:0游客1手机
    private int type;
    //签名:前端传入
//    @NotBlank(message = "签名不能不为空")
//    @SignConstraion(message = "签名错误")
    private String sign;

    //手机号码:唯一约束
//    @PhoneConstraion(message = "电话号码验证错误")
    private String phone;
    //手机登录时的验证码
    private String code;

//    private Date createTime;
//
//    public Date getCreateTime() {
//        return createTime;
//    }
//
//    public void setCreateTime(Date createTime) {
//        this.createTime = createTime;
//    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getDeviceMac() {
        return deviceMac;
    }

    public void setDeviceMac(String deviceMac) {
        this.deviceMac = deviceMac;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "PlayerLoginInfo{" + "timestamp='" + timestamp + '\'' + ", uid='" + uid + '\'' + ", deviceMac='" + deviceMac + '\'' + ", type=" + type + ", sign='" + sign + '\'' + ", phone='" + phone + '\'' + ", code='" + code + '\'' + '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PlayerLoginInfo loginInfo = (PlayerLoginInfo) o;
        return deviceMac != null ? deviceMac.equals(loginInfo.deviceMac) : loginInfo.deviceMac == null;
    }

    @Override
    public int hashCode() {
        return deviceMac != null ? deviceMac.hashCode() : 0;
    }


    public static PlayerLoginInfo copy(LoginDto dto) {
        PlayerLoginInfo playerLoginInfo = new PlayerLoginInfo();
        playerLoginInfo.setType(dto.getType());
        playerLoginInfo.setUid(dto.getUid());
        playerLoginInfo.setCode(dto.getCode());
        playerLoginInfo.setDeviceMac(dto.getDeviceMac());
        playerLoginInfo.setPhone(dto.getPhone());
        playerLoginInfo.setSign(dto.getSign());
        playerLoginInfo.setTimestamp(new Date(dto.getTimestamp()));
        return playerLoginInfo;
    }
}
